package com.itheima.demo2;

import java.time.Instant;
import java.time.LocalDate;
import java.util.*;

/**
 * @author chihb
 * @create-time 2024/7/2 11:10
 * @description
 */
public class Test {
    public static void main(String[] args) {
        String userStrs = "10001:张三:男:1990-01-01#10002:李四:女:1989-01-09#10003:王五:男:1999-09-09#10004:刘备:男:1899-01-01#10005:孙悟空:男:1900-01-01#10006:张三:女:1999-01-01#10007:刘备:女:1999-01-01#10008:张三:女:2003-07-01#10009:猪八戒:男:1900-01-01";
        List<User> userList=new ArrayList<>();
        String[] users = userStrs.split("#");
        for(String useStr:users){
            User user=new User();
            String[] split = useStr.split(":");
            user.setId(Long.valueOf(split[0]));
            user.setName(split[1]);
            user.setGender(split[2]);
            user.setBirthday(LocalDate.parse(split[3]));
            userList.add(user);
        }
        Map<String, Integer> result=new HashMap<>();
        for(User i:userList){
            String name=i.getName();
            if(result.containsKey(name)){
                result.put(name,result.get(name)+1);
            }else {
                result.put(name,1);
            }
        }
        result.forEach((k,v)-> System.out.println(k+"====>"+v));
    }
}
